package com.sc.study.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sc.common.annotation.Log;
import com.sc.common.core.controller.BaseController;
import com.sc.common.core.domain.AjaxResult;
import com.sc.common.enums.BusinessType;
import com.sc.study.exam.domain.ScTestexamQuestion;
import com.sc.study.exam.service.IScTestexamQuestionService;
import com.sc.common.utils.poi.ExcelUtil;
import com.sc.common.core.page.TableDataInfo;

/**
 * 考试题目Controller
 * 
 * @author sc
 * @date 2022-02-27
 */
@RestController
@RequestMapping("/study/testexamquestion")
public class ScTestexamQuestionController extends BaseController
{
    @Autowired
    private IScTestexamQuestionService scTestexamQuestionService;

    /**
     * 查询考试题目列表
     */
    @PreAuthorize("@ss.hasPermi('study:testexamquestion:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScTestexamQuestion scTestexamQuestion)
    {
        startPage();
        List<ScTestexamQuestion> list = scTestexamQuestionService.selectScTestexamQuestionList(scTestexamQuestion);
        return getDataTable(list);
    }

    /**
     * 导出考试题目列表
     */
    @PreAuthorize("@ss.hasPermi('study:testexamquestion:export')")
    @Log(title = "考试题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScTestexamQuestion scTestexamQuestion)
    {
        List<ScTestexamQuestion> list = scTestexamQuestionService.selectScTestexamQuestionList(scTestexamQuestion);
        ExcelUtil<ScTestexamQuestion> util = new ExcelUtil<ScTestexamQuestion>(ScTestexamQuestion.class);
        util.exportExcel(response, list, "考试题目数据");
    }

    /**
     * 获取考试题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:testexamquestion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(scTestexamQuestionService.selectScTestexamQuestionById(id));
    }

    /**
     * 新增考试题目
     */
    @PreAuthorize("@ss.hasPermi('study:testexamquestion:add')")
    @Log(title = "考试题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScTestexamQuestion scTestexamQuestion)
    {
        return toAjax(scTestexamQuestionService.insertScTestexamQuestion(scTestexamQuestion));
    }


    /**
     * 批量新增考试题目
     */
    @PreAuthorize("@ss.hasPermi('study:testexamquestion:add')")
    @Log(title = "考试题目", businessType = BusinessType.INSERT)
    @PostMapping("/batch")
    public AjaxResult batchAdd(@RequestBody ScTestexamQuestion[] scTestexamQuestion)
    {
        return toAjax(scTestexamQuestionService.batchAdd(scTestexamQuestion));
    }


    /**
     * 修改考试题目
     */
    @PreAuthorize("@ss.hasPermi('study:testexamquestion:edit')")
    @Log(title = "考试题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScTestexamQuestion scTestexamQuestion)
    {
        return toAjax(scTestexamQuestionService.updateScTestexamQuestion(scTestexamQuestion));
    }

    /**
     * 删除考试题目
     */
    @PreAuthorize("@ss.hasPermi('study:testexamquestion:remove')")
    @Log(title = "考试题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scTestexamQuestionService.deleteScTestexamQuestionByIds(ids));
    }


}
